package com.hst.web.common.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wangyh
 * Http request utils
 */
public class HttpRequestUtils {
	
	/**
	 * 获取客户端IP
	 * @param request
	 * @return
	 */
	public static String getClientIp(HttpServletRequest request) {
		String s = request.getHeader("X-Forwarded-For");
	    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
	        s = request.getHeader("Proxy-Client-IP");
	    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
	        s = request.getHeader("WL-Proxy-Client-IP");
	    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
	        s = request.getHeader("HTTP_CLIENT_IP");
	    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
	        s = request.getHeader("HTTP_X_FORWARDED_FOR");
	    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
	        s = request.getRemoteAddr();
	    return s.split(",")[0];
	}
}

